package com.xbongbong.paas.model.impl;

import com.xbongbong.paas.domain.dao.PaasProcessTaskDao;
import com.xbongbong.paas.domain.entity.PaasProcessTaskEntity;
import com.xbongbong.paas.model.PaasProcessTaskModel;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author: wufeng
 * @date: 2018/11/19 14:41
 * @desrcption: 流程任务
 */
@Service("paasProcessTaskModel")
public class PaasProcessTaskModelImpl implements PaasProcessTaskModel {

    private static final String COLUMNS = "id,corpid,app_id,form_id,menu_id,saas_mark,business_type,sub_business_type,flow_status,creator_id,add_time,update_time,del,template_id, dingtalk_process_instance_id ";

    @Resource
    private PaasProcessTaskDao paasProcessTaskDao;

    @Override
    public Integer insert(PaasProcessTaskEntity entity) {
        long now = DateUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return paasProcessTaskDao.insert(entity);
    }

    @Override
    public List<PaasProcessTaskEntity> list(Map<String, Object> entity) {
        entity.put("columns", COLUMNS);
        return paasProcessTaskDao.findEntitys(entity);
    }

    @Override
    public PaasProcessTaskEntity getByKey(Integer key, String corpid) {
        return paasProcessTaskDao.getByKey(key, corpid);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> entity) {
        return paasProcessTaskDao.getEntitysCount(entity);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer delete(PaasProcessTaskEntity entity) {
        return paasProcessTaskDao.deleteByKey(entity.getId().intValue(), entity.getCorpid());
    }

    @Override
    public Integer update(PaasProcessTaskEntity entity) {
        long now = DateUtil.getInt();
        entity.setUpdateTime(now);
        return paasProcessTaskDao.update(entity);
    }

    @Override
    public List<PaasProcessTaskEntity> findEntitys(Map<String, Object> param) {
        return paasProcessTaskDao.findEntitys(param);
    }

    /**
     * 没有mapper
     * @param entityList
     */
    @Override
    public void insertBatch(List<PaasProcessTaskEntity> entityList) {
        paasProcessTaskDao.insertBatch(entityList);
    }

    /**
     * 查询已经删除的钉钉实例id
     * @param param
     * @return
     */
    @Override
    public List<PaasProcessTaskEntity> getDingtalkProcessInstanceId(Map<String, Object> param) {
        return paasProcessTaskDao.getDingtalkProcessInstanceId(param);
    }

    @Override
    public Integer updateInstockAndOutstockType(List<UpdateDataEntity> list) throws XbbException{
        Integer result = paasProcessTaskDao.updateInstockAndOutstockType(list);
        return result;
    }

    @Override
    public Integer deleteByFormId(Long formId, String corpid) {
        return paasProcessTaskDao.deleteByFormId(formId, corpid);
    }
}
